<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<title>发送邮件</title>
		<script src="http://libs.baidu.com/jquery/2.0.0/jquery.min.js"></script>
		<script src="http://zj.demo.yichao58.com/public/lib/layui/layui.js" ></script>
		<link rel="stylesheet" href="http://zj.demo.yichao58.com/public/lib/layui/css/layui.css" />
	</head>

	<body>
		
		<div style="width: 700px;margin:50px auto;">
			<form class="layui-form" action="">
				<div class="layui-form-item">
					<label class="layui-form-label">收件人地址</label>
					<div class="layui-input-block">
						<input type="text" name="address" required lay-verify="required" placeholder="请输入地址" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">邮件标题</label>
					<div class="layui-input-block">
						<input type="text" name="title" required lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item layui-form-text">
					<label class="layui-form-label">邮件内容</label>
					<div class="layui-input-block">
						<textarea name="body" lay-verify="required" placeholder="请输入内容" class="layui-textarea" rows="15"></textarea>
					</div>
				</div>
				<div class="layui-form-item">
					<div class="layui-input-block">
						<button class="layui-btn" lay-submit lay-filter="formDemo">立即发送</button>
					</div>
				</div>
			</form>
		</div>

		<script>
			layui.use('form', function() {
				var form = layui.form;
				//监听提交
				form.on('submit(formDemo)', function(data) {
					var loadIndex =layer.load(); 
					$.ajax({
					  	url:"http://zj.demo.yichao58.com/index.php/common/mailer/send",
					  	data:data.field,            //请求参数
					  	type:"POST",    //请求方式
					  	dataType:"json",     //指定响应数据类型！text,html,script,json,jsonp,xml
					  	timeout:0,        //设定超时时间，单位是毫秒。默认为0，永不取消。
					  	success:function(data){//成功回调
					  		if(data.code==0){
					  			layer.msg("发送成功！");
					  		}else{
					  			layer.msg("发送失败："+data.msg);
					  		}
					  		layer.close(loadIndex); 
					  	},
					  	compLete:function(XML,text){//请求完成时回调,在success和error之后
					  		layer.close(loadIndex); 
					  	}
					});
					return false;
				});
			});
		</script>
	</body>

</html>